from sls_mirrors.sls_agent import MirrorUpdate


class BasicPositionMirrorUpdate(MirrorUpdate):
    """
    基本状态镜像更新
    """
    def __init__(self,parent_mirror):
        super().__init__(parent_mirror)

    def init_data(self):
        """
        初始化数据
        """
        self.GNSS_position ={"latitude":0,"longitude":0}
        self.vehicle_yaw = 0
        self.rel_alt = 0
    
    def get_sub_topic(self,id:str):
        """
        初始化主题
        """
        return "/status/"+id+"/BP"

    def update(self,messageDict:dict):
        """
        更新镜像
        """
        if "GNSS_position" in messageDict:
            self.GNSS_position = messageDict["GNSS_position"]
        if "vehicle_yaw" in messageDict:
            self.vehicle_yaw = messageDict["vehicle_yaw"]
        if "rel_alt" in messageDict:
            self.rel_alt = messageDict["rel_alt"]

class BasicStatusMirrorUpdate(MirrorUpdate):
    '''
    flying status mirror update
    '''
    def __init__(self,parent_mirror):
        super().__init__(parent_mirror)

    def init_data(self):
        self.is_flying = False
        self.is_armed = False
        self.is_offborad = False

    def get_sub_topic(self, id):
        return "/status/"+id+"/BS"

    def update(self, messageDict: dict):
        if "is_flying" in messageDict:
            self.is_flying = messageDict["is_flying"]
        if "is_armed" in messageDict:
            self.is_armed = messageDict["is_armed"]
        if "is_offborad" in messageDict:
            self.is_offborad = messageDict["is_offborad"]
